tacit programming : Point-free, Concatenatives & J
https://gyazo.com/0db5c983c9b10230c31cd41d54caf6c2
concatenative programming language
concatenative
concatenate + -ive
連鎖する性質を持つ、連鎖性
quotation & combinator
A concatenative programming language is a point-free computer programming language in which all expressions denote functions, and the juxtaposition of expressions denotes function composition. Concatenative programming replaces function application, which is common in other programming styles, with function composition as the default way to build subroutines.
實裝
Joy
The Joy programming language in computer science is a purely functional programming language that was produced by Manfred von Thun of La Trobe University in Melbourne, Australia. Joy is based on composition of functions rather than lambda calculus. It has turned out to have many similarities to Forth, due not to design but to a sort of parallel evolution and convergence. It was also inspired by the function-level programming style of John Backus's FP.
Factor
Factor is a stack-oriented programming language created by Slava Pestov. Factor is dynamically typed and has automatic memory management, as well as powerful metaprogramming features. The language has a single implementation featuring a self-hosted optimizing compiler and an interactive development environment. The Factor distribution includes a large standard library.
The Factor programming language combines powerful language features with a full-featured library. The implementation is fully compiled for performance, while still supporting interactive development. Factor applications are portable between all common platforms. Factor can deploy stand-alone applications on all platforms. Full source code for the Factor project is available under a BSD license.
Factor belongs to the family of concatenative languages: this means that, at the lowest level, a Factor program is a series of words (functions) that manipulate a stack of references to dynamically-typed values. This gives the language a powerful foundation which allows many abstractions and paradigms to be built on top. Reload this page to see a random code example below.
Kitten
Kitten is a statically typed, stack-based functional programming language designed to be simple and fast. It is a concatenative language, combining aspects of imperative and pure functional programming. There is an introduction available and a tutorial in progress.
PISC (Position Independent Source Code)
Popr
unix pipe & filter
stream
tacit programming
Tacit programming, also called point-free style, is a programming paradigm in which function definitions do not identify the arguments (or "points") on which they operate. Instead the definitions merely compose other functions, among which are combinators that manipulate the arguments. Tacit programming is of theoretical interest, because the strict use of composition results in programs that are well adapted for equational reasoning. It is also the natural style of certain programming languages, including APL and its derivatives, and concatenative languages such as Forth. The lack of argument naming gives point-free style a reputation of being unnecessarily obscure, hence the epithet "pointless style".
Unix scripting uses the paradigm with pipes.
The key idea in tacit programming is to assist in operating at the appropriate level of abstraction. That is, to translate the natural transformation given by currying
$ \hom(A\times B,C)\cong \hom(B,C^{A})
into computer functions, where the left represents the uncurried form of a function and the right the curried. $ C^A denotes the functionals from $ A to $ C (see also exponential object), while $ A\times B denotes the Cartesian product of $ A and $ B.
tacit programming is a programming method to construct functions without explicit arguments.
a.k.a. "point-free style"
prefer function composition than function application
$ \lambdaabstraction$ \toquotation
function application$ \tofunction composition
It is very common for functional programmers to write functions as a composition of other functions, never mentioning the actual arguments they will be applied to.
資料
add
code:haskell
2 + 3
(+) 2 3
code:kitten
2 3 (+)
code:popr
2 3 +
code:j
2+3
+/2 3
average
code:haskell
foldr (+) 0 xs / (fromIntegral . length $ xs)
((/) . foldr (+) 0) <*> (fromIntegral . length) $ 2, 3 code:kitten
2, 3 dup 0 {(+)} fold_left swap length (/) code:popr
2 3 dup sum swap length /f code:j
xs=.2 3
(+/xs)%(#xs)
(+/%#)2 3
factorial
code:haskell
(foldr (*) 1) . (enumFromTo 1) $ 9
(foldr (*) 1) . (enumFromTo 1) $ 0
code:factor
USING: io kernel locals math math.parser ;
IN: factorial
: factorial_rec ( n n -- n ) dup 0 = drop [ n m | n m * m 1 - factorial_rec call
] if ;
9 factorial
code:factor
USING: kernel math math.ranges memoize sequences ;
IN: math.factorials
MEMO: factorial ( n -- n! )
9 factorial
0 factorial
code:kitten
9 { -> n, rec; if (n <= 0) { 1 } else { (n - 1) rec call * n } } fix
code:popr
9 fact
:bc fact
___ tests.fact (1 -> 1) x2 rec (hash: jr44u) ___
1 changing var >= 1 :: ?i x4 pgjhj 2 __primitive.eq &1 &3 :: y x1 bbebh 4 __primitive.assert &3 2 is 1 :: i? x1 iw379 6 __primitive.gt &1 &3 :: y x1 paus6 7 __primitive.assert 10 6 :: i? x1 nm6vj 8 __primitive.sub &1 3 >= 0 :: i x1 lukbp 9 tests.fact 8 :: i x1 jvosc 10 __primitive.mul 1 9 :: i x1 fgkih 3 fact
3 2 fact *
3 2 1 fact * *
3 2 1 * *
3 2 *
6
code:j
!9
!0
code:j
*/1+i.9
*/1+i.0
*/i.0
code:j
factorial =: 1: ` (* factorial@<:) @. *
factorial 9
factorial 0
factorial 2
1: ` (* factorial @ <:) @. * 2
* 2
1
(* factorial @ <:) 2
2 * (factorial @ <: 2)
2 * (factorial 1)
2 * (1: ` (* factorial@<:) @. * 1)
* 1
1
2 * (1 * (factorial@<: 1))
2 * (1 * (factorial 0))
2 * (1 * (1: ` (* factorial@<:) @. * 0))
* 0
0
2 * (1 * (1: 0))
2 * (1 * (1))
2 * 1
2
quicksort
code:j
quicksort=:(($:@(<#[),(=#[),$:@(>#[))({~?@#))^:(1<#)
quicksort 1 _9 2 _8 3 _7 4 _6 5
_9 _8 _7 _6 1 2 3 4 5
FizzBuzz
code:haskell
map (\n -> if (n mod 3 == 0) then "Fizz" else (show n)) 1..100 code:popr
code:j
''(('|'E.B)#i.#B)}B=.}.}:1{":(<'FizzBuzz')(<:(0 E.15|A)#A)}(<'Buzz')(<:(0 E.5|A)#A)}(<'Fizz')(<:(0 E.3|A)#A)}<"0 A=.>:i.100